import pandas as pd
df=pd.DataFrame({'商品':['苹果','香蕉','梨子'],
    '单价(元)':[5,5,4],
    '销量(kg)':[100,None,None],
    '库存(kg)':[50,None,70]
    })
print('原始数据：\n',df)
# print('检查缺失值：\n',df.isnull())
# print('检查非缺失值：\n',df.notnull())
# print('统计：\n',df.isnull().sum())

# print('删除包含缺失值的行：\n',df.dropna())
# print('删除包含缺失值的列：\n',df.dropna(axis=1))
# print('删除少于3个非缺失值的行：\n',df.dropna(thresh=3))
# print('删除库存列包含缺失值的行：\n',df.dropna(subset=['库存(kg)']))
# print('删除少于3个非缺失值的行：\n',df.dropna(thresh=2))
# print('删除库存列包含缺失值的行：\n',df.dropna(subset=['销量(kg)']))

print(df.fillna(120))
print(df.fillna({'销量(kg)':120,'库存(kg)':60}))
print(df.fillna(method='ffill'))
print(df.fillna(method='bfill'))
